<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Class</title>
</head>
<body>
    <script>
        // 传统写法
        function Point(x, y) {
            this.x = x;
            this.y = y;
        }

        Point.prototype.toString = function() {
            return '(' + this.x + ',' + this.y + ')';
        }

        let p = new Point(3, 4);
        console.log(p.toString());

        // ES6 写法
        class Pointer {
            constructor(x, y) {
                this.x = x;
                this.y = y;
            }

            toString () {
                return '(' + this.x + ',' + this.y + ')';
            }
        }

        let p2 = new Pointer();
        console.log(p2.toString());
        console.log(typeof Pointer); // 'function'
        console.log(Pointer === Pointer.prototype.constructor); // true

        class Person {
            constructor () {

            }
            toString () {

            }
        }
        // 相当于
        Person.prototype = {
            constructor() {},
            toString() {},
        }

        let person = new Person();
        let person2 = new Person();
        console.log(person.hasOwnProperty('constructor')); // false
        console.log(person.__proto__ === person2.__proto__);

        // constructor 
        class Cat {
            constructor (name) {
                return Object.create(null);
            }
        }

        console.log(typeof (new Cat())); // 'object'
        console.log(new Cat() instanceof Cat); // false
    </script>
</body>
</html>